<?php

use Illuminate\Database\Seeder;

class Permissions extends Seeder
{
    private $items;

    private function data()
    {

        $json = '[
  {
    "type": "menu",
    "name": "index",
    "src": "homepage.html",
    "title": "首页",
    "modules": "authority,marketing"
  },
  {
    "type": "title",
    "name": "admin",
    "title": "营销管理"
  },
  {
    "type": "menu",
    "name": "addcourse_list",
    "src": "addcourse_list.html",
    "title": "课程产品",
    "modules": "product"
  },
  {
    "type": "menu",
    "name": "marketing_agencylist",
    "src": "marketing_agencylist.html",
    "title": "营销列表",
    "modules": "marketing"
  },
  {
    "type": "menu",
    "name": "potentialguestlist",
    "src": "potential_guest_list.html",
    "title": "潜客管理",
    "modules": "marketing"
  },
  {
    "type": "menu",
    "name": "order",
    "src": "institutional_order.html",
    "title": "订单列表",
    "modules": "order"
  },
  {
    "type": "title",
    "name": "baseInfo",
    "title": "基础信息"
  },
  {
    "type": "menu",
    "name": "teacherInfo",
    "src": "teacherlist.html",
    "title": "教师信息",
    "modules": "teacher"
  },
  {
    "type": "menu",
    "name": "Studentmanagement",
    "src": "studentlist.html",
    "title": "学生信息",
    "modules": "student"
  },
  {
    "type": "title",
    "name": "arrange",
    "title": "排课"
  },
  {
    "type": "menu",
    "name": "teachers_lessontime",
    "src": "cloud.html",
    "title": "云盘资源",
    "modules": "cloud"
  },
  {
    "type": "menu",
    "name": "classlist",
    "src": "classlist.html",
    "title": "班级管理",
    "modules": "classe,lesson"
  },
  {
    "type": "menu",
    "name": "teacher_lessontime",
    "src": "teacher_lessontimes.html",
    "title": "预约课排课",
    "modules": "schedule"
  },
  {
    "type": "menu",
    "name": "ordermanagement",
    "src": "orderlist.html",
    "title": "常规课约课",
    "modules": "appointment"
  },
  {
    "type": "menu",
    "name": "enrolllist",
    "src": "enrolllist.html",
    "title": "试听课约课",
    "modules": "demoment"
  },
  {
    "type": "title",
    "name": "lessontime",
    "title": "课表"
  },
  {
    "type": "menu",
    "name": "teachers_lessontime",
    "src": "school_lessontime.html",
    "title": "机构课表",
    "modules": "schedules"
  },
  {
    "type": "menu",
    "name": "teachers_lessontime",
    "src": "teacher_schedule.html",
    "title": "教师课表",
    "modules": "schedules"
  },
  {
    "type": "menu",
    "name": "teachers_lessontime",
    "src": "student_schedule.html",
    "title": "学生课表",
    "modules": "schedules"
  },
  {
    "type": "title",
    "name": "",
    "title": "课时统计"
  },
  {
    "type": "menu",
    "name": "teachers_lessontime",
    "src": "teacher_class_stat.html",
    "title": "教师课时统计",
    "modules": "statistic"
  },
  {
    "type": "menu",
    "name": "teachers_lessontime",
    "src": "student_class_stat.html",
    "title": "学生课时统计",
    "modules": "statistic"
  },
  {
    "type": "title",
    "name": "teachers_lessontime",
    "title": "系统配置"
  },
  {
    "type": "menu",
    "name": "teachers_lessontime",
    "src": "usermanagement.html",
    "title": "登录账号管理",
    "modules": "user,authority"
  },
  {
    "type": "menu",
    "name": "teachers_lessontime",
    "src": "permission.html",
    "title": "角色管理",
    "modules": "authority"
  },
  {
    "type": "menu",
    "name": "teachers_lessontime",
    "src": "agency_adminlist.html",
    "title": "机构人员管理",
    "modules": "employee"
  },
  {
    "type": "menu",
    "name": "teachers_lessontime",
    "src": "company_info.html",
    "title": "公司信息",
    "modules": "organization"
  },
  {
    "type": "menu",
    "name": "teachers_lessontime",
    "src": "course_color.html",
    "title": "课程类型",
    "modules": "coursetype"
  },
  {
    "type": "menu",
    "name": "teachers_lessontime",
    "src": "class_type.html",
    "title": "课节类型",
    "modules": "scheduletype"
  },
  {
    "type":"menu",
    "name":"level_admin",
    "src":"level_admin.html",
    "title":"约课级别管理",
    "modules":"level"
  },
  {
    "type": "title",
    "name": "admin",
    "title": "首页配置"
  },
  {
    "type": "menu",
    "name": "banner",
    "src": "banner.html",
    "title": "轮播图",
    "modules": "adimage"
  },
  {
    "type": "menu",
    "name": "agency_intro",
    "src": "agency_intro.html",
    "title": "机构介绍",
    "modules": "agency"
  },
  {
    "type": "menu",
    "name": "about_us",
    "src": "about_us.html",
    "title": "关于我们",
    "modules": "page"
  },
  {
    "type": "menu",
    "name": "feedback",
    "src": "feedback.html",
    "title": "课堂反馈",
    "modules": "comment"
  },
  {
    "type": "menu",
    "name": "payment",
    "src": "payment.html",
    "title": "支付账号信息",
    "modules": "payment"
  }
]';

        return $json;
    }

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        try{
            $items = json_decode($this->data(), 1);
        }catch (Exception $e){
            var_dump($e->getMessage());
        }
        $pid = 0;
        foreach ($items as $item){
            $obj = new \App\Model\System\AuthPermission($item);
            $obj->pid = $pid;
            $obj->save();
            if($item['type']=='title'){
                $pid = $obj->id;
                $obj->pid = 0;
                $obj->save();
            }
        }
    }

}
